/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package musicbeach;

import com.trolltech.qt.QVariant;
import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.QSettings;
import com.trolltech.qt.core.QSize;
import com.trolltech.qt.gui.*;

/**
 * @author Radek
 */
public class Application extends QMainWindow {
    
    private QMenu fileMenu;    
    private QMenu helpMenu;

    private String[] args;
    
    public Application(String[] args)
    {
        this.args = args;
    }
    
    public void run(){
        //setWindowFlags(Qt.WindowType.CustomizeWindowHint);
        
        this.readSettings();
        
        this.setWindowTitle("Music Beach");
        
        QMenuBar menuBar = new QMenuBar();
        this.setMenuBar(menuBar);
        
        this.setWindowIcon(new QIcon("classpath:com/trolltech/images/qt-logo.png"));
        
        this.initUI();
        this.createMenus();
        this.show();
    }
    
    /**
     * Tworzy menu
     */
    private void createMenus()
    {
        fileMenu = menuBar().addMenu(tr("&Plik"));
        
        QAction login = new QAction("&Zaloguj", this);
        login.triggered.connect(this, "showLogingWindow()");
        fileMenu.addAction(login);
        
        fileMenu.addSeparator();
        
        QAction quit = new QAction("&Zakończ", this);
        quit.triggered.connect(QApplication.instance(), "quit()");
        fileMenu.addAction(quit);
//        fileMenu.addAction(openAct);
//        fileMenu.addAction(saveAct);
//        fileMenu.addAction(saveAsAct);
//        fileMenu.addSeparator();
//        fileMenu.addAction(exitAct);

//        editMenu = menuBar().addMenu(tr("&Edit"));
//        editMenu.addAction(cutAct);
//        editMenu.addAction(copyAct);
//        editMenu.addAction(pasteAct);
//
        menuBar().addSeparator();
//
        helpMenu = menuBar().addMenu(tr("Pomo&c"));
        QAction aboutAct = new QAction("&O programie", this);
        aboutAct.triggered.connect(QApplication.instance(), "quit()");
        helpMenu.addAction(aboutAct);
//        helpMenu.addSeparator();
//        helpMenu.addAction(aboutQtJambiAct);
//        helpMenu.addAction(aboutQtAct);
    }
    
    private void initUI() {

        QPushButton quit = new QPushButton("Zaloguj", this);
        quit.setGeometry(10, 30, 75, 30);

        quit.clicked.connect(this, "showLogingWindow()");
    }
    
    /**
     * Pokazuje okno logowania
     */
    private void showLogingWindow()
    {
        LogingWindow window = new LogingWindow();
        
        window.init(this);
        window.show();
        
        this.setDisabled(true);
    }
    
    /**
     * Wczytuje ustawienia
     */
    private void readSettings()
    {
        QSettings settings = new QSettings("MusicBeach", "Settings");
        QPoint pos = QVariant.toPoint(settings.value("pos", new QPoint(20, 20)));
        QSize size = QVariant.toSize(settings.value("size", new QSize(1300, 650)));
        resize(size);
        move(pos);
    }
    
    /**
     * Zapisuje ustawienia
     */
    private void writeSettings()
    {
        QSettings settings = new QSettings("MusicBeach", "Settings");
        settings.setValue("pos", pos());
        settings.setValue("size", size());
    }
    
    @Override
    public void closeEvent(QCloseEvent event)
    {
        writeSettings();
        event.accept();
    }
}
